<template>
  <el-row :gutter="20">
    <el-col :span="4">
      <div class="grid-content bg-purple">&emsp;&emsp;&emsp;</div>
    </el-col>
    <el-col :span="16">
      <div class="grid-content bg-purple">
        <div class="aa" style="width:500px">
          <el-form ref="form" label-width="80px">
            <el-form-item label="类型名称">
              <el-input v-model="form.dictName" placeholder="请输入名称"></el-input>
            </el-form-item>
            <el-form-item label="类型编码">
              <el-input v-model="form.dictCode" placeholder="请输入编码"></el-input>
            </el-form-item>
            <el-form-item label="排序">
              <el-input-number
                v-model="form.sort"
                @change="handleChange"
                :min="form.sort"
                :max="100000000"
                label="描述文字"
              ></el-input-number>
            </el-form-item>
            <el-form-item label="描述">
              <el-input type="textarea" v-model="form.description"></el-input>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="onSubmit">立即创建</el-button>
              <el-button @click="next">返回</el-button>
            </el-form-item>
          </el-form>
        </div>
      </div>
    </el-col>
    <el-col :span="4">
      <div class="grid-content bg-purple">&emsp;&emsp;&emsp;</div>
    </el-col>
  </el-row>
</template>
<script>
import dictType from "@/api/dictType";
export default {
  data() {
    return {
      form: {
        sort: 0,
        dictCode: "",
        dictName: "",
        description: ""
      }
    };
  },
  created() {
    this.init();
  },
  methods: {
    handleChange(value) {
      this.form.sort = value;
    },
    onSubmit() {
      dictType.save(this.form).then(response => {
        this.$router.push({ path: "/stuteacher/dictType" });
      });
    },
    init() {
      // debugger
      if (this.$route.params && this.$route.params.id) {
        const id = this.$route.params.id;
        //回显
        this.getByid(id);
      } else {
      }
    },
    getByid(id){
      // debugger
      dictType.getbyid(id).then(response=>{
        // console.log(response)
       this.form=response.data.data
      })
    },
    next(){
      this.$router.push({
        path: "/stuteacher/dictType" 
      });
    },

    remove(id) {
      this.$confirm("此操作将永久删除该记录, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          return dictType.del(id).then(() => {
            this.$message({
              type: "success",
              message: "删除成功!"
            });
            this.getlist();
          });
        })
        .then(() => {
          this.$message({
            type: "success",
            message: "删除成功!"
          });
          this.query();
        })
        .catch(response => {
          // 失败
          if (response === "cancel") {
            this.$message({
              type: "info",
              message: "已取消删除"
            });
          }
        });
    },
  }
};
</script>
<style >
.aa {
  margin: 40px;
}
</style>